var config = {
    host: "url",
    platform: "web",
    version: "1.0.0"
};
var store = {
    isSession: function () {
        if (window.sessionStorage) {
            return true;
        } else {
            alert("浏览器不支持sessionStorage");
            return false;
        }
    },
    isLocal: function () {
        if (window.localStorage) {
            return true;
        } else {
            alert("浏览器不支持localStorage");
            return false;
        }
    },
    sets: function (key, value) {
        if (this.isSession()) {
            window.sessionStorage.setItem(key, value);
        }
    },
    gets: function (key) {
        if (this.isSession()) {
            return window.sessionStorage.getItem(key);
        }
    },
    removes: function (key) {
        if (this.isSession()) {
            window.sessionStorage.removeItem(key);
        }
    },
    clears: function () {
        if (this.isSession()) {
            window.sessionStorage.clear();
        }
    },
    setl: function (key, value) {
        if (this.isLocal()) {
            window.localStorage.setItem(key, value);
        }
    },
    getl: function (key) {
        if (this.isLocal()) {
            return window.localStorage.getItem(key);
        }
    },
    removel: function (key) {
        if (this.isLocal()) {
            window.localStorage.removeItem(key);
        }
    },
    clearl: function () {
        if (this.isLocal()) {
            window.localStorage.clear();
        }
    }
};
var storage = {
    isSession: function () {
        if (window.sessionStorage) {
            return true;
        } else {
            alert("浏览器不支持sessionStorage");
            return false;
        }
    },
    isLocal: function () {
        if (window.localStorage) {
            return true;
        } else {
            alert("浏览器不支持localStorage");
            return false;
        }
    },
    sets: function (key, value) {
        if (this.isSession()) {
            window.sessionStorage.setItem(key, JSON.stringify(value));
        }
    },
    gets: function (key) {
        if (this.isSession()) {
            return JSON.stringify(window.sessionStorage.getItem(key));
        }
    },
    removes: function (key) {
        if (this.isSession()) {
            window.sessionStorage.removeItem(key);
        }
    },
    clears: function () {
        if (this.isSession()) {
            window.sessionStorage.clear();
        }
    },
    setl: function (key, value) {
        if (this.isLocal()) {
            window.localStorage.setItem(key, JSON.stringify(value));
        }
    },
    getl: function (key) {
        if (this.isLocal()) {
            return JSON.stringify(window.localStorage.getItem(key));
        }
    },
    removel: function (key) {
        if (this.isLocal()) {
            window.localStorage.removeItem(key);
        }
    },
    clearl: function () {
        if (this.isLocal()) {
            window.localStorage.clear();
        }
    }
};
var common = {
    getRequest: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    },
    getUrlParam: function (param) { //param为要获取的参数名 注:获取不到是为null
        var currentUrl = window.location.href; //获取当前链接
        var arr = currentUrl.split("?");//分割域名和参数界限
        if (arr.length < 2) {
            return null;
        }
        arr = arr[1].split("&");//分割参数
        for (var i = 0; i < arr.length; i++) {
            var tem = arr[i].split("="); //分割参数名和参数内容
            if (tem[0] == param) {
                return tem[1];
            }
        }
        return null;
    },
    copy: function (source, target) {
        var target = target || {};
        for (var i in source) {
            if (typeof source[i] === "object") {
                target[i] = (source[i].constructor === Array) ? [] : {};
                copy(source[i], target[i]);
            } else {
                target[i] = source[i]
            }
        }
        return target;
    }
};
var inout = {
    getData: function (result) {
        if (result.code !== 0) {
            alert("错误码：" + result.code + "\n错误原因：" + result.msg);
        }
        return result.data;
    },
    doData: function (data, result) {
        if (result.code !== 0) {
            alert("错误码：" + result.code + "\n错误原因：" + result.msg);
        }
        data = result.data;
    },
    doList: function (data, result) {
        if (result.code !== 0) {
            alert("错误码：" + result.code + "\n错误原因：" + result.msg);
        } else {
            data.data = result.data.records;
            data.size = result.data.size;
            data.index = result.data.current;
            data.total = result.data.total;
        }
    }
};
var io = {
    getData: function (result) {
        if (!result.code) {
            alert("错误原因：" + result.msg);
        }
        return result.data;
    },
    doData: function (data, result) {
        if (!result.code) {
            alert("错误原因：" + result.msg);
        }
        data = result.data;
    },
    doList: function (data, result) {
        if (!result.code) {
            alert("错误原因：" + result.msg);
        } else {
            data.data = result.data.records;
            data.size = result.data.size;
            data.index = result.data.current;
            data.total = result.data.total;
        }
    }
};
var ajax = {
    getParam: function (data) {
        var param = {
            platform: config.platform,
            version: config.version,
            data: data
        };
        return JSON.stringify(param);
    },
    get: function (url, param) {
        var data;
        $.ajax({
            url: url,
            type: 'GET',
            async: false,
            data: this.getParam(param),
            contentType: "application/json",
            success: function (res) {
                data = res;
            }
        });
        return data;
    },
    post: function (url, param) {
        var result;
        $.ajax({
            url: url,
            type: 'POST',
            async: false,
            data: this.getParam(param),
            contentType: "application/json",
            success: function (res) {
                result = res;
            }
        });
        return result;
    },
    file: function (url, param) {
        var data;
        $.ajax({
            url: url,
            type: 'POST',
            async: false,
            data: param,
            contentType: false, //不指定提交数据类型
            processData: false, //提交数据不做处理
            success: function (res) {
                data = res;
            }
        });
        return data;
    }
};